package conf

import (
	"log"

	"github.com/sirupsen/logrus"
	"github.com/spf13/viper"
	"gorm.io/gorm"
	"lab.com/gen"
)

// LabMysql is mysql client for lab
var LabMysql *gorm.DB
var LabGen *gen.Query

// MoodRedis is redis client for moodlink
// var MoodRedis *redis.Client

// CasbinEnforcer is casbin enforcer for role
// var CasbinEnforcer *casbin.Enforcer

// AppLog application panic or other error log
var AppLog *logrus.Logger

// AccessLog api calls
var AccessLog *logrus.Logger

// SQLLog sql log
var SQLLog *logrus.Logger

// Load load config and init mysql and redis client
func Load() {

	viper.AddConfigPath(".")
	viper.SetConfigName("config")
	viper.SetConfigType("yaml")

	if err := viper.ReadInConfig(); err != nil {
		log.Fatalf("Read config file error: %s", err)
	}

	initServerConf()
	initConfigParamConf()
	initCosConf()

	// init all the log targets
	AppLog = initApplicationLog()
	AccessLog = initAccessLog()
	SQLLog = initSQLLog()

	// init mysql and redis
	LabMysql = initLabLinkDb()
	LabGen = gen.Use(LabMysql)
	// MoodRedis = initMoodLinkRedis()

	// CasbinEnforcer = initCasbinRule()

}
